package day6.condition;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/**
 * Condition的用法
 */
public class Demo {
    public static void main(String[] args) throws InterruptedException {

        Lock lock = new ReentrantLock();

        Condition condition = lock.newCondition();

        condition.await();   // 等价于 wait
        condition.signal();  // 等价于notify
        condition.signalAll();

        lock.lock();   // 也需要获取到锁才能用

        try {
            condition.await();
        } finally {
            lock.unlock();
        }
    }
}
